#include<bits/stdc++.h>
using namespace std;

int s[100010];
int dp[1000010];

int main()
{
	int n, x;
	cin>>n;
	unordered_map<int, int> sum;
	for(int i = 1;i <= n;i++)
	{
		cin>>x;
		sum[x]++;
	}
	int k = 1;
	for(auto i = sum.begin();i != sum.end();i++)
		s[i->first] = (i->first)*(i->second);

	dp[1] = s[1];
	for(int i = 2;i <= 100000;i++)
		dp[i] = max(dp[i-2]+s[i], dp[i-1]);
		
	cout<<dp[100000];
	return 0;
}
 
